import HomePage from "@/views/admin/HomePage";
import AdminLogin from "@/views/admin/AdminLogin";
import store from "@/store/index"
// const navList = store.state.identity === 2? doctorRouter:store.state.identity === 3?historyRouter:[]
export const homePageRouter = {
  path: '/',
  name: 'homepage',
  component: HomePage,
  meta: {requiresAuth: true},
  redirect: '/login',
  children: []
}
const router = [
  {
    path: '/login',
    name: 'login',
    component: AdminLogin
  }

]
export const adminRouter = () => {
  const path = '/admin'
  return routerSplice(path,router)
}
export function routerSplice(path,routeList){
  return routeList.map(item => {
    item.path = path.concat(item.path)
    item.name = path.concat(item.name)
    if (item.children){
      item.redirect = path.concat(item.redirect)
      item.children = routerSplice(path,item.children)
    }
    return item
  })
}

export function adminBeforeEnter(to, from, next) {  //独享路由守卫
  if ((store.state.token && store.state.identity >= 2) || to.path === "/admin/login"){
    next()
  }else {
    next({path:"/admin/login"})
  }
}



